#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],c[100005],p[100005],q[100005],t;
bool f = false;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
    long long ans = 0;
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
    }
    int num = 1;
    for(int i = 1;i<=n;i++){
        for(int j = i+1;j<=n;j++){
            if(a[i]==a[j]&&num%2==1){
                c[i]=1;
                c[j]=1;
                f = true;
            }
            if(a[i]==a[j]&&num%2==0){
                c[i]=3;
                c[j]=3;
                f = true;
            }
        }
        if(f) num++;
        f = false;
    }
    int k = 1;
    for(int i = 1;i<=n;i++){
        if(c[i]){
            p[k] = a[i];
            q[k] = c[i];
            k++;
        }
    }
    int i = 1,j = 2;
    while(i<=k-1&&j<=k-1){
        if(i>=j) j++;
        if(q[i]==q[j]&&p[i]==p[j]){
            ans+=p[i];
            i++;j++;
        }
        else if(q[i]==q[j]&&p[i]!=p[j]){
            q[i] = 0;
            i++;
        }
        else{
            j++;
        }
    }
    cout<<ans;
}
    return 0;
}
